<template>
  <div>
    <div class="pageheader">
      <XHeader :left-options="{backText:''}" :title="xheader.title" class="XHeader"></XHeader>
    </div>
    <div class="page">
      <div class="block" style="  margin-top: 12px;">
        <div class="brokeragebox">
          <div class="box">
            <div class="des">可提佣金</div>
            <div class="brokerage">￥ {{generalize.can_get_amount}}</div>
          </div>
          <button v-if="generalize.can_get_amount>0" type="button" @click="onWithdraw">提现</button>
        </div>
      </div>
      <scroller
        @on-pullup-loading="getProducts"
        lock-x
        ref="scroller"
        :pullup-config="{content:'',upContent:'',downContent:'释放加载更多',loadingContent:'加载中...',}"
        height="-45"
        :use-pullup="true"
      >
        <div style="margin-top:12px;">
          <div class="block" v-for="(item,index) in products" :key="index">
            <div class="brokerageitem">
              <div class="header">
                <div class="ordernumber">订单号:{{item.order_sn}}</div>
                <div class="await">{{item.bill_state_desc}}</div>
              </div>
              <div class="content">
                <chimage class="image" :src="item.order_goods.goods_image"></chimage>
                <div style="flex:1;">
                  <div class="title">{{item.order_goods.goods_name}}</div>
                  <div class="pricebar">
                    <div style="flex:1">佣金</div>
                    <div class="price">￥{{item.bill_amount}}</div>
                  </div>
                </div>
              </div>
              <div class="footer">
                <div class="time">{{item.create_time}}</div>
                <!-- <div class="name">王思聪</div> -->
              </div>
            </div>
          </div>
          <load-more
            v-if="!more&&!products.length"
            :show-loading="false"
            :tip="'无历史推广'"
            background-color="#fbf9fe"
          ></load-more>
        </div>
      </scroller>
    </div>
  </div>
</template>
<script>
  import Me from '@/dll/me'

  export default {
    name: 'generalize',
    data () {
      return {
        xheader: {
          title: '赚钱宝'
        },
        generalize: {
          can_get_amount: 0
        },
        products: [],
        more: true,
        page: 1
      }
    },
    created () {
      this.getGeneralizeInfo()
      this.getProducts()
    },
    methods: {
      onWithdraw () {
      },
      async withdraw () {
        if (this.generalize.can_get_amount <= 0) {
          return
        }
        // eslint-disable-next-line no-unused-vars
        let param = {
          total: this.generalize.can_get_amount
        }
        this.$vux.loading.show({
          text: '加载中'
        })
        let res = await Me.generalizeWithdraw()
        this.$vux.loading.hide()
        if (res.code == 0) {
          this.$vux.alert.show({
            title: '提示',
            content: '已申请提现',
            onHide: () => {
              this.getGeneralizeInfo()
            }
          })
        } else {
          this.$vux.alert.show({
            title: '提示',
            content: res.msg
          })
        }
      },
      // 获取佣金
      async getGeneralizeInfo () {
        this.$vux.loading.show({
          text: '加载中'
        })
        let res = await Me.getGeneralizeInfo()
        this.$vux.loading.hide()
        if (res.code == 0) {
          this.generalize = res.data
        } else {
          this.$vux.alert.show({
            title: '提示',
            content: res.msg,
            onHide: () => {
              this.$router.back()
            }
          })
        }
      },
      async getProducts () {
        let param = {
          page: this.page
        }
        if (!this.more) {
          return
        }
        this.$vux.loading.show({
          text: '加载中'
        })
        let res = await Me.getMeDistribuionProductList(param)
        this.$vux.loading.hide()
        if (res.code == 0) {
          if (res.data.share_list.length < res.data.pageParam.listRows) {
            this.more = false
            this.$refs.scroller.disablePullup()
          }
          this.products = [].concat(this.products, res.data.share_list)
          this.page = this.page + 1
          this.$refs.scroller.donePullup()
        } else {
          this.$vux.alert.show({
            title: '提示',
            content: res.msg
          })
          this.$refs.scroller.disablePullup()
        }
      }
    }
  }
</script>

<style lang="less" scoped>
  page {
    padding-bottom: 12px;
  }

  .brokeragebox {
    display: block;
    background-color: #fff;
  }

  .brokeragebox .des {
    font-size: 12px;
    color: #351009;
    line-height: 17px;
    opacity: 0.5;
  }

  .brokeragebox .box {
    padding: 20px 16px;
  }

  .brokeragebox .brokerage {
    margin-top: 7px;
    font-size: 40px;
    color: #ae2309;
    line-height: 56px;
  }

  .brokeragebox button {
    font-size: 16px;
    color: #fff;
    height: 48px;
    line-height: 48px;
  }

  .brokerageitem {
    background-color: #fff;
  }

  .brokerageitem .header {
    display: flex;
    padding: 12px 16px;
    font-size: 12px;
    line-height: 17px;
    align-items: center;
  }

  .brokerageitem .ordernumber {
    flex: 1;
    color: #9f8d89;
  }

  .brokerageitem .await {
    color: #b0290f;
  }

  .brokerageitem .complete {
    color: #52322c;
  }

  .brokerageitem .return {
    color: #f4b13b;
  }

  .brokerageitem .content {
    display: flex;
    flex-direction: row;
    padding: 12px 16px;
    border-top: 1px solid #fbf8f7;
    border-bottom: 1px solid #fbf8f7;
    align-items: center;
  }

  .brokerageitem .content .image {
    width: 90px;
    height: 90px;
    display: block;
    margin-right: 24px;
    background-color: #f5f5f5;
    background-size: cover;
    background-position: center;
  }

  .brokerageitem .content .title {
    font-size: 14px;
    color: #9f8d89;
    line-height: 20px;
    font-weight: 500;
    height: 40px;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
  }

  .brokerageitem .content .pricebar {
    margin-top: 5px;
    display: flex;
    align-items: center;
    flex-direction: row;
    font-size: 14px;
    color: #351009;
    line-height: 20px;
  }

  .brokerageitem .content .price {
    font-weight: 600;
    color: #b0290f;
  }

  .brokerageitem .footer {
    padding: 12px 16px;
    display: flex;
    flex-direction: row;
    align-items: center;
  }

  .brokerageitem .time {
    flex: 1;
    font-size: 12px;
    color: #9f8d89;
    line-height: 17px;
  }

  .brokerageitem .name {
    font-size: 12px;
    color: #421f19;
  }
</style>
